<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm" style="padding-bottom: 500px">
    <div class="page-title"><div class="page-title-con"><span id="flowsetname"></span><div class="move_title"></div><?php include "../public/subturn.php";?></div></div>
    <div class="main-container">



        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">申请人</label>
                        <div class="layui-input-block">
                            <input type="text" id="flowuser" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">申请部门</label>
                        <div class="layui-input-block">
                            <input type="text" id="flowdept" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>项目信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="bidid" class="layui-input bidid" onclick="openPage('../public/choose_bid.php?dom=bidid&page=bid_fan&xuantype=4','80%','80%')">
                            <div class="choose_div" id="bidid" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_bid.php?dom=bidid&page=bid_fan&xuantype=4','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目状态</label>
                        <div class="layui-input-block">
                            <input type="text" id="bid_state" readonly placeholder="请输入" autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">委托方</label>
                        <div class="layui-input-block">
                            <input type="text" id="bid_weier" readonly placeholder="请输入" autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>本次返还信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>返款编号</label>
                        <div class="layui-input-block">
                            <input type="text" id="number" placeholder="请输入" disabled autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>款项摘要</label>
                        <div class="layui-input-block">
                            <input type="text" name="zhai" id="zhai" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>关联保证金收取</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="quid" class="layui-input quid" onclick="choose_bid_qu()">
                            <div class="choose_div" id="quid" key="1"></div>
                            <span class="choose_one" onclick="choose_bid_qu()"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">收取金额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="qumoney" id="qumoney" readonly placeholder="请输入" autocomplete="off" class="layui-input moneyinput disabled">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">本次扣收合计(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="koufee" id="koufee" readonly placeholder="请输入" autocomplete="off" class="layui-input moneyinput disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>本次实际返款(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="money" id="money" readonly placeholder="请输入" autocomplete="off" class="layui-input moneyinput disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>支付方式</label>
                        <div class="layui-input-block">
                            <div id="incdaotype"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>付款对象</label>
                        <div class="layui-input-block">
                            <input type="text" name="duier" id="duier" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">账户账号</label>
                        <div class="layui-input-block">
                            <input type="text" name="banknum" id="banknum" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">开户行</label>
                        <div class="layui-input-block">
                            <input type="text" name="bankname" id="bankname" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">关联单据</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="flowrelas" class="layui-input flowrelas" onclick="openPage('../public/choose_flowrelas.php?dom=flowrelas','80%','80%');">
                            <div class="choose_div" id="flowrelas" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_flowrelas.php?dom=flowrelas','80%','80%');"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="advanersDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">预审人</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=advaners&type=user&single=2','770px','490px');"></div>
                                <div class="tanxiannei" id="advaners"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=advaners&type=user&single=2','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="nexterDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>指定下一步审核人</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=nexter&type=user&single=1','770px','490px');"></div>
                                <div class="tanxiannei" id="nexter"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=nexter&type=user&single=1','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>
            <?php include '../public/upinfo.php'?>

        </div>

        <div class="block-generic">
            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="1">
                    <div class="opt-btn-group">
                        <div><span>返款明细</span></div>
                        <div>
                            <button type="button" onclick="choose_bid_qu_list()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">从保证金收取明细选择</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_row">删除行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_all">删除全部</button>
                        </div>
                    </div>
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th width="45">序号</th>
                            <th><text>*</text>投标单位</th>
                            <th>收取金额(元)</th>
                            <th>退回金额(元)</th>
                            <th><text>*</text>公司垫付手续费(元)</th>
                            <th><text>*</text>本次扣报名费(元)</th>
                            <th><text>*</text>本次扣资质使用费(元)</th>
                            <th><text>*</text>本次扣资审费(元)</th>
                            <th><text>*</text>本次扣其他费(元)</th>
                            <th>本次实际返款(元)</th>
                            <th>备注</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="list_list"></tbody>
                    </table>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>
        </div>
    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;
    var param_isturn = getQueryVariable('isturn') || 0;
    if(param_isturn > 0){
        $("#billzhan").remove();
        $("#billtutn").remove();
        $("#billsub").attr('isshen', 1);
    }
    var param_billyushen = getQueryVariable('billyushen') || 0;
    if(param_billyushen == 2){
        $("#billyushen").addClass('layui-hide');
    }

    $("#commentForm").validate({
        rules: {
            zhai: {required: true},
            duier: {required: true},
        },
        messages:{
            zhai: {required: "请输入"},
            duier: {required: "请输入"},
        }
    });

    function choose_bid_qu(){
        var bidid = get_choose_val('bidid');
        if(!bidid){
            facade.error("请先选择项目名称");return false;
        }
        openPage('../public/choose_bid_qu.php?page=bid_fan&dom=quid&bidid='+bidid,'80%','80%');
    }


    function choose_bid_qu_list(){
        var quid = get_choose_val('quid');
        if(!quid){
            facade.error("请先选择关联保证金收取");return false;
        }
        openPage('../public/choose_bid_qu_list.php?page=bid_fan&choose_type=checkbox&quid='+quid,'80%','80%');
    }




    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();
        facade.ajax({type: 'get', url: ask_flowdata_edit_bid_fan, data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;
                $("#flowsetname").text(data.flowsetname);
                $("#flowuser").val(data.flowuser);
                $("#flowdept").val(data.flowdept);
                if(data.isadvan){
                    $("#advanersDiv").removeClass('layui-hide');
                    if(data.advaners_info.length > 0){
                        tan_tags_init('#advaners', data.advaners_info);
                    }
                }
                if(data.isnext){
                    $("#nexterDiv").removeClass('layui-hide');
                    if(data.nexter_info.length > 0){
                        tan_tags_init('#nexter', data.nexter_info);
                    }
                }
                if(data.flowrelas_info.length > 0){
                    set_choose_btn_more('flowrelas',data.flowrelas_info);
                }



                var bidinfo = res.data.bidinfo
                var quidinfo = res.data.quidinfo;
                if(bidinfo){
                    set_choose_btn('bidid',bidinfo.id,bidinfo.name);
                    $("#bid_state").val(bidinfo.state_name_wen);
                    $("#bid_weier").val(bidinfo.weier);
                    $("#bid_fan_fee").val(bidinfo.bid_fan_fee);
                }
                if(quidinfo){
                    set_choose_btn('quid',quidinfo.id,quidinfo.number+'(金额：'+quidinfo.money+')');
                }


                $("#number").val(data.number);
                $("#koufee").val(data.koufee);
                $("#qumoney").val(data.qumoney);
                $("#zhai").val(data.zhai);
                $("#money").val(data.money);
                $("#duier").val(data.duier);
                $("#banknum").val(data.banknum);
                $("#bankname").val(data.bankname);
                $("#explain").val(data.explain);


                xmselect_dan('incdaotype', res.data.incdaotype, data.incdaotype, function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#incdaotype").find('xm-select').removeClass('error');
                    }else{
                        $("#incdaotype").find('xm-select').addClass('error');
                    }
                });


                short_table_opt_func('', 1);


                var list = res.data.list;
                if(list.length > 0){
                    for (var key in list){
                        var str = '';
                        var nums = parseInt(key)+1;
                        str += '<tr>';
                        str += '<td style="width: 45px">'+nums+'</td>';
                        str += '<td><input type="text" class="layui-input touunit disabled" readonly value="'+list[key].touunit+'"></td>';
                        str += '<td><input type="number" class="layui-input qufee disabled" readonly value="'+list[key].qufee+'"></td>';
                        str += '<td><input type="number" class="layui-input tuifee disabled" readonly value="'+list[key].tuifee+'"></td>';
                        str += '<td><input type="number" class="layui-input dianfee" value="'+list[key].dianfee+'"></td>';
                        str += '<td><input type="number" class="layui-input koubao" value="'+list[key].koubao+'"></td>';
                        str += '<td><input type="number" class="layui-input kouzhifee" value="'+list[key].kouzhifee+'"></td>';
                        str += '<td><input type="number" class="layui-input koushenfee" value="'+list[key].koushenfee+'"></td>';
                        str += '<td><input type="number" class="layui-input kouqifee" value="'+list[key].kouqifee+'"></td>';
                        str += '<td><input type="number" class="layui-input money disabled" readonly value="'+list[key].money+'"></td>';
                        str += '<td><input type="text" class="layui-input explain" value="'+list[key].explain+'"></td>';
                        str += '</tr>';
                        $("#list_list").append(str);
                    }
                }
                update_refresh_row_func()


                initParseMoney();
                public_upload_file_load('upload_files', res.data.files);
                render_from();
            }
        });


        form.on('submit(add)', function(data){
            data.field.isturn = $(this).attr('key') || 0;
            data.field.isshen = $(this).attr('isshen') || 0;
            data.field.flowrelas = get_choose_val('flowrelas');
            data.field.advaners = tan_tags_getvalue("#advaners", 'user');
            data.field.nexter = tan_tags_getvalue("#nexter", 'user');
            parseMoney(data);

            data.field.bidid = get_choose_val('bidid');
            data.field.quid = get_choose_val('quid');
            if(data.field.isturn > 0){
                var validRes = $("#commentForm").valid();
                formValid('bidid');
                if(data.field.bidid == undefined || !data.field.bidid){
                    validRes = false;
                }

                formValid('quid');
                if(data.field.quid == undefined || !data.field.quid){
                    validRes = false;
                }

                if(!data.field.incdaotype){
                    $("#incdaotype").find('xm-select').addClass('error');
                    validRes = false;
                }else{
                    $("#incdaotype").find('xm-select').removeClass('error');
                }

                if(!validRes){return false;}
            }

            var list = [''];
            try {
                $('#list_list tr').each(function (i) {
                    var touunit = $(this).find('.touunit').val();
                    var qufee = $(this).find('.qufee').val();
                    var dianfee = $(this).find('.dianfee').val();
                    var koubao = $(this).find('.koubao').val();
                    var kouzhifee = $(this).find('.kouzhifee').val();
                    var koushenfee = $(this).find('.koushenfee').val();
                    var kouqifee = $(this).find('.kouqifee').val();
                    var money = $(this).find('.money').val();
                    var explain = $(this).find('.explain').val();

                    var index = i + 1;
                    if(data.field.isturn > 0){
                        if(dianfee == ''){
                            throw new Error('第'+index+'行，请输入公司垫付手续费');
                        }
                        if(koubao == ''){
                            throw new Error('第'+index+'行，请输入本次扣报名费');
                        }
                        if(kouzhifee == ''){
                            throw new Error('第'+index+'行，请输入本次扣资质使用费');
                        }
                        if(koushenfee == ''){
                            throw new Error('第'+index+'行，请输入本次扣资审费');
                        }
                        if(kouqifee == ''){
                            throw new Error('第'+index+'行，请输入本次扣其他费');
                        }
                    }

                    list.push({
                        touunit:touunit,
                        qufee:qufee,
                        dianfee:dianfee,
                        koubao:koubao,
                        kouzhifee:kouzhifee,
                        koushenfee:koushenfee,
                        kouqifee:kouqifee,
                        money:money,
                        explain:explain,
                    });
                });
            } catch(e) {
                $(".listerror").find('span').text(e.message);
                $(".listerror").show();
                return false;
            }
            $(".listerror").hide();
            data.field.list = list;





            data.field.id = param_id;
            data.field.files = public_upload_file_value('upload_files');
            data = parseMoney(data);

            public_flow_submit(data.field, ask_flowdata_add_bid_fan, ask_flowdata_edit_bid_fan, $(this).attr('but'));
            return false;
        });

    });




    $('#list_list').on('input propertychange','.dianfee,.koubao,.kouzhifee,.koushenfee,.kouqifee',function () {
        jisuan_money_all();
    });
    function jisuan_money_all() {
        var allmoney = 0;
        var koufee = 0;
        $('#list_list tr').each(function (i) {
            var tuifee = parseFloat($(this).find('.tuifee').val()) || 0;
            var dianfee = parseFloat($(this).find('.dianfee').val()) || 0;
            var koubao = parseFloat($(this).find('.koubao').val()) || 0;
            var kouzhifee = parseFloat($(this).find('.kouzhifee').val()) || 0;
            var koushenfee = parseFloat($(this).find('.koushenfee').val()) || 0;
            var kouqifee = parseFloat($(this).find('.kouqifee').val()) || 0;

            //本次实际返款= 退回金额+公司垫付手续费-本次扣报名费-本次扣资质使用费-本次扣资审费-本次扣其他费
            var money =  parseFloat(tuifee) + parseFloat(dianfee) - (parseFloat(koubao) + parseFloat(kouzhifee) + parseFloat(koushenfee) + parseFloat(kouqifee));
            $(this).find('.money').val(money.toFixed(2));

            allmoney = parseFloat(allmoney) + parseFloat(money);

            koufee = parseFloat(koufee) + parseFloat(koubao) + parseFloat(kouzhifee) + parseFloat(koushenfee) + parseFloat(kouqifee);


        });
        $("#money").val(allmoney.toFixed(2));
        $("#koufee").val(koufee.toFixed(2));
        initParseMoney();
    }

    function update_refresh_row_func() {
        render_date();
        jisuan_money_all();
        $.each($("#list_list").children('tr'),function (key,val) {
            $(this).children('td:first-child').html(key+1);
        });
        setTimeout(function () {
            $(".short_table_list table tbody tr").click(function () {
                $(".short_table_list table tbody tr").removeClass('line-row');
                $(".short_table_list table tbody tr").attr('sle','');
                $(this).addClass('line-row');
                $(this).attr('sle','sle');
            });
        },1000);
    }
</script>
</body>
</html>
